package com.amsp.oa.oademo.service.impl;

import com.amsp.oa.oademo.entity.PowerCost;
import com.amsp.oa.oademo.mapper.PowerCostMapper;
import com.amsp.oa.oademo.service.PowerCostService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;

@Service
public class PowerCostServiceImpl extends ServiceImpl<PowerCostMapper, PowerCost> implements PowerCostService {

    @Override
    public IPage<PowerCost> getPage(Integer current, Integer size, String loadName) {
        Page<PowerCost> page = new Page<>(current, size);
        LambdaQueryWrapper<PowerCost> wrapper = new LambdaQueryWrapper<>();

        if (StringUtils.hasText(loadName)) {
            wrapper.like(PowerCost::getLoadName, loadName);
        }

        wrapper.orderByDesc(PowerCost::getCreateTime);
        return page(page, wrapper);
    }

}